﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NazTek.Extension.Clr4.Test
{
    /// <summary>
    /// Contains Unit Tests for ByteExtension class public members
    /// </summary>
    [TestClass()]
    public class ByteExtensionTest
    {
        private TestContext testContextInstance;
        /// <summary>
        /// Gets/Sets current test context, e.g., property bag
        /// </summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }
        /// <summary>
        /// Attempt to convert a byte to a specific class type, should return null
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_FromClass()
        {
            Convert.ToByte(10).ToEnum<MockPerson>();
        }
        /// <summary>
        /// Attempt to convert a byte to an enum type whose underlying type is byte, should return the corresponding item
        /// </summary>
        [TestMethod()]
        public void TestToEnum_DefinedEnumItem()
        {
            Enum actual = Convert.ToByte(1).ToEnum<MockSalutation>();
            Assert.AreEqual<Enum>(MockSalutation.Mrs, actual);
        }
        /// <summary>
        /// Attempt to convert a byte to an enum type in which the value is not defined, should return null
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_UndefinedEnumItem()
        {
            Convert.ToByte(10).ToEnum<MockSalutation>();
        }
        /// <summary>
        /// Attempt to convert a byte to an enum type whose underlying type is int and the value is undefined, with the exception flag on, should raise an exception
        /// </summary>
        [TestMethod()]
        [ExpectedException(typeof(CustomException))]
        public void TestToEnum_TypeMismatch()
        {
            Convert.ToByte(1).ToEnum<MockGender>();
        }
    }
}